<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
session_start();
class UserInfo extends Controller
{
    /**
     * 显示用户的个人信息
     *
     * @return \think\Response
     */
    public function User_Info()
    {
        $result = Db::table('userinfo')->where('name', $_SESSION['name'])->find();
        return json($result);
    }
    
    /**
     * 修改用户密码
     */
    public function User_ModPass()
    {
        Request::instance()->get();
        $request = Request::instance()->post();
        $id = Db::table('user')->where('name', $_SESSION['name'])->find();
        if ($id['password'] === $request['pass']) {
            $row = Db::table('user')->where('name', $_SESSION['name'])->update(['password' => $request['repass']]);
            if ($row) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
    
    public function Mod_Secret()
    {
        $request = Request::instance()->post();
        dump($request);
        $row = Db::table('userinfo')->where('name', $_SESSION['name'])->update(['status' => $request['refuse_friend'], 'message' => $request['allow_message']]);
        if ($row) {
            $this->success('设置成功');
        } else {
            $this->error('设置失败');
        }
    }

    
}
